		var retentDayArray=[];
          var editIndex = undefined;
          $('#tt').edatagrid({
           	url:"/miguReadRetentConfig/retentList?name="+$('#name').val(),
            onClickRow: function(index){
            	 if($('#name').val()==''){return};
                 if(index!=editIndex){
                     editIndex = index;
                  }
             },
             onLoadSuccess:function(data){
             	$(this).datagrid('enableDnd');
             	retentDayArray=[];

             	if(data.rows.length==0){
             		if($('#name').val()==''){
             			 $('#tt').datagrid({
 	                        url:'',
 	                        data:''
             			 }); 
             		}else{
                   	 var data1 = [
                	              {"retentDay": "1", 'retentRate':''},
                	              {"retentDay": "2", 'retentRate':''},
                	              {"retentDay": "3", 'retentRate':''},
                	              {"retentDay": "4", 'retentRate':''},
                	              {"retentDay": "5", 'retentRate':''},
                	              {"retentDay": "6", 'retentRate':''},
                	              {"retentDay": "7", 'retentRate':''},
                	              {"retentDay": "8", 'retentRate':''},
                	              {"retentDay": "9", 'retentRate':''},
                	              {"retentDay": "10", 'retentRate':''},
                	              {"retentDay": "11", 'retentRate':''},
                	              {"retentDay": "12", 'retentRate':''},
                	              {"retentDay": "13", 'retentRate':''},
                	              {"retentDay": "14", 'retentRate':''},
                	              {"retentDay": "15", 'retentRate':''},
                	              {"retentDay": "16", 'retentRate':''},
                	              {"retentDay": "17", 'retentRate':''},
                	              {"retentDay": "18", 'retentRate':''},
                	              {"retentDay": "19", 'retentRate':''},
                	              {"retentDay": "20", 'retentRate':''},
                	              {"retentDay": "21", 'retentRate':''},
                	              {"retentDay": "22", 'retentRate':''},
                	              {"retentDay": "23", 'retentRate':''},
                	              {"retentDay": "24", 'retentRate':''},
                	              {"retentDay": "25", 'retentRate':''},
                	              {"retentDay": "26", 'retentRate':''},
                	              {"retentDay": "27", 'retentRate':''},
                	              {"retentDay": "28", 'retentRate':''},
                	              {"retentDay": "29", 'retentRate':''},
                	              {"retentDay": "30", 'retentRate':''},
                	              {"retentDay": "31", 'retentRate':''},
                	              {"retentDay": "32", 'retentRate':''},
                	              {"retentDay": "33", 'retentRate':''},
                	              {"retentDay": "34", 'retentRate':''},
                	              {"retentDay": "35", 'retentRate':''},
                	              {"retentDay": "36", 'retentRate':''},
                	              {"retentDay": "37", 'retentRate':''},
                	              {"retentDay": "38", 'retentRate':''},
                	              {"retentDay": "39", 'retentRate':''},
                	              {"retentDay": "40", 'retentRate':''},
                	              {"retentDay": "41", 'retentRate':''},
                	              {"retentDay": "42", 'retentRate':''},
                	              {"retentDay": "43", 'retentRate':''},
                	              {"retentDay": "44", 'retentRate':''},
                	              {"retentDay": "45", 'retentRate':''},
                	              {"retentDay": "46", 'retentRate':''},
                	              {"retentDay": "47", 'retentRate':''},
                	              {"retentDay": "48", 'retentRate':''},
                	              {"retentDay": "49", 'retentRate':''},
                	              {"retentDay": "50", 'retentRate':''},
                	              {"retentDay": "51", 'retentRate':''},
                	              {"retentDay": "52", 'retentRate':''},
                	              {"retentDay": "53", 'retentRate':''},
                	              {"retentDay": "54", 'retentRate':''},
                	              {"retentDay": "55", 'retentRate':''},
                	              {"retentDay": "56", 'retentRate':''},
                	              {"retentDay": "57", 'retentRate':''},
                	              {"retentDay": "58", 'retentRate':''},
                	              {"retentDay": "59", 'retentRate':''},
                	              {"retentDay": "60", 'retentRate':''}
                	          ];
             			$('#tt').datagrid({
 	                        url:'',
 	                        data:data1
             			 }); 
             			
             		}
            	}else{
                  	$.each(data.rows,function(index,mod){
                		retentDayArray.push(mod.retentDay)
                	})
            	}
             },
             onBeforeSave:function(index){
            	 var retentDayVal=$("td[field='retentDay'] input").val();
            	 var retentRateVal=$("td[field='retentRate'] input").val();
            	 if(retentDayVal==''){
            		 return false; 
            	 }
            	 if(retentRateVal==''){
            		 return false; 
            	 }
             }
          });
         //查询
         function doSearch(){
          	$('#tt').edatagrid({
          		url:"/miguReadRetentConfig/retentList?name="+$('#name').val()});
          	$('#tt').datagrid('unselectAll');
         }

         //添加
         function addRow(){
         	var name=$('#name').val();
         	if(name==''){return}
         	var file='/resources/js/easyui/datagrid-dnd.js';
         	$('#tt').edatagrid('appendRow', {
         		name:name,    
                retentDay:''
            });
            $('#tt').datagrid('enableDnd');
         }

          //保存
		function saveRow(){
		    var name=$('#name').val();
         	if(name==''){return}
            var newRow=[];
            var arrayLen=0;
            $('#tt').edatagrid('saveRow')
            var initRow=$("#tt").datagrid('getRows');
 		  	$.each(initRow,function(index,mod){
		  		if(mod.retentRate===''||mod.retentDay==''||mod.retentRate==0){
			  		
		  		}else{
		  			var	array={};
			  		array={retentRate:mod.retentRate, retentDay:mod.retentDay, name:name};
			  		newRow.push(array);
			  		arrayLen=newRow.length;
		  		}
		  	})
		  
		  	$.ajax({
		  		url:'/miguReadRetentConfig/saveRetent',
		  		type:'post',
		  		dataType:"json",
		  		data:JSON.stringify(newRow),
		  		contentType:'application/json',
		  		success:function(){
		  			jQuery.messager.alert('提示:','成功保存'+arrayLen+'条数据!'); 
		  			doSearch();
		  		}
		  	})
            
        }
        //删除
        function remove(){
		  	var rows = $('#tt').edatagrid('getChecked');
		  	var arr = [];
		  	for (var i=0;i<rows.length;i++) {
		  		var channelRetentConfig = {};
		  		channelRetentConfig['retentRate'] = rows[i].retentRate;
		  		channelRetentConfig['retentDay'] = rows[i].retentDay;
		  		channelRetentConfig['name'] = rows[i].name;
		  		arr.push(channelRetentConfig)
		  	}
		  	
		  	$.ajax({
		  		headers: {
	                'Accept': 'application/json',
	                'Content-Type': 'application/json'
	            },
		  		url:'/miguReadRetentConfig/batchDelete',
		  		type:'POST',
		  		data: JSON.stringify(arr),
		  		async: true,
	            dataType: "json",
		  		success:function(){
	  				jQuery.messager.alert('提示:','删除成功!'); 
		  			doSearch();
		  		}
		  	})
        }
        
        //全选
        function selectAll(){
        	 $('#tt').datagrid('selectAll');
        }
        //输入框限制为数字
		$(document).on("keyup afterpaste","td[field='retentDay'] input","td[field='exetimes'] input",function(){
			this.value=this.value.replace(/\D/g,'');
		})
		//占比输入框限制，最大为100且只最多能有两位小数点 
		$(document).on("keyup afterpaste","td[field='retentRate'] input",function(e){
				 this.value = this.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符   
				 this.value = this.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的   
				 this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");  
				 this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数   
				 if(this.value.indexOf(".")< 0 && this.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额  
					 this.value= parseFloat(this.value);  
				 }  
				 if(this.value>100){
					 this.value = 100;
				 }
		})
		
		$(document).on('blur', '.datagrid-view td[field=retentDay] input', function(){
			var inputVal=this.value;
			$.each(retentDayArray,function(index,mod){
				if(mod==inputVal){
					inputVal='';
					jQuery.messager.alert('提示:','留存天数不能重复!');	
				}
			})
			$(this).val(inputVal);
		});
  
	  
function doCopy(){
	var name=$('#name').val();
	$('#tt').datagrid({
		url:'/miguReadRetentConfig/copyMiguReadRetentConfig',
	    queryParams:{
	      name:name
	    }
	});
	$('#tt').datagrid('unselectAll');
}
		